const { Task } = require('../models')
module.exports = class TaskProxy {
  static async findLatestTask () {
    return Task.findOne().sort('-index')
  }
  static async findNextTask () {
    return Task.findOne().sort('index')
  }
  static async newAndSave (taskInfo) {
    const newTask = new Task(taskInfo)
    return newTask.save()
  }
  static async getTaskList (page, size) {
    return Task.find().limit(size).skip(size * (page - 1)).sort('index')
  }

  static async findOne (query) {
    return Task.findOne(query)
  }

  static async deleteById (id) {
    return Task.deleteOne({ _id: id })
  }

  static async updateTaskById (id, params) {
    return Task.updateOne({ _id: id }, { $set: params })
  }
}
